package com.ybkj.daijia.api.common;

import com.ybkj.daijia.server.zhuanxian.Line;
import java.util.ArrayList;
import java.util.List;

/**
 * 线路工具
 */
public class LineUtil {

    /**
     * 删除逆向线路
     *
     * @param lines
     * @return
     */
    public static List<Line> deleteRepreat(List<Line> lines) {
        //用于存放需要隐藏的线路id
        List<Long> lineIdList = new ArrayList<>();
        //用于存放需要隐藏的线路
        List<Line> lineList = new ArrayList<>();
        for (Line line : lines) {
            String startAddress = line.getStartAddress();
            String endAddress = line.getEndAddress();
            boolean exist = false;
            for (Long id : lineIdList) {
                if (line.getId() == id) {
                    exist = true;
                }
            }
            if (exist) {
                continue;
            }
            for (Line l : lines) {
                if (l.getStartAddress().equals(endAddress) && l.getEndAddress()
                    .equals(startAddress)) {
                    lineList.add(l);
                    lineIdList.add(l.getId());
                }
            }
        }
        for (Line line : lineList) {
            lines.remove(line);
        }
        return lines;
    }
}
